﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Team4Mock.Entity;

namespace Team4Mock.UserControl.BusinessType
{
    public partial class ListBusiness : System.Web.UI.UserControl
    {
        BusinessEntity be=new BusinessEntity();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                gvBus.DataSource = be.Getdata();
                gvBus.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

            if (txtBusName.Text=="" && txtSICCode.Text=="")
            {
                tb.Text = "Input Business name or SIC Code";
            }
            else
            {
                if (txtBusName.Text!="")
                {
                    be.BusinessName = txtBusName.Text;
                    be.SICCode = "";
                    gvBus.DataSource = be.Search(1, be);
                    gvBus.DataBind();
                }
                if (txtSICCode.Text != "")
                {
                    be.BusinessName = "";
                    be.SICCode = txtSICCode.Text;
                    gvBus.DataSource = be.Search(2, be);
                    gvBus.DataBind();
                }
                if (txtSICCode.Text!="" && txtBusName.Text!="")
                {
                    be.BusinessName = txtBusName.Text;
                    be.SICCode = txtSICCode.Text;
                    gvBus.DataSource = be.Search(3, be);
                    gvBus.DataBind();
                }
            }
        }

        protected void btnNone_Click(object sender, EventArgs e)
        {
            tb.Text = "";
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtBusName.Text = "";
            txtSICCode.Text = "";
            tb.Text = "";
            txtBusName.Focus();
            
        }
    }
}